package com.example.antmall.business.product.controller;

import com.example.antmall.business.product.bo.ProductAddBO;
import com.example.antmall.business.product.bo.ProductEditBO;
import com.example.antmall.business.product.bo.ProductQueryBO;
import com.example.antmall.business.product.service.ProductService;
import com.example.antmall.business.product.vo.ProductQueryVO;
import com.example.antmall.common.entity.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Api(tags = "商品管理")//api接口，方便自测
@RestController//RestController-->@Controller + @ResponseBody 主要用于处理RESTful风格的请求 用在类上
@Validated //使非空实体类校验生效
@RequestMapping("product")
public class ProductController {
    @Autowired//用在类成员方法、成员变量上
    private ProductService productService;

    @ApiOperation("新增商品")//api相关 方便自测
    @PostMapping("add")//用于POST请求的注解
    //@Valid 使我们的NotBlank注解生效
    public void add(@Valid @RequestBody ProductAddBO addBO) {
        productService.add(addBO);
    }

    @ApiOperation("修改商品")//api相关 方便自测
    @PostMapping("edit")//用于POST请求的注解
    //@Valid 使我们的NotBlank注解生效
    public void update(@Valid @RequestBody ProductEditBO editBO) {
        productService.edit(editBO);
    }
    @ApiOperation("分页查询")//api相关 方便自测
    @GetMapping("page")//用于POST请求的注解

    public PageVO<ProductQueryVO> page(ProductQueryBO queryBO) {
        return productService.page(queryBO);
    }

    @ApiOperation("删除商品")//api相关 方便自测
    @PostMapping("delete")//用于POST请求的注解
    public void delete(@NotEmpty @RequestBody List<Long> idList ) {
        //@NotEmpty是非空实体类校验
         productService.delete(idList);
    }
}
